# Contributor: Matthias Ahouansou <matthias@ahouansou.cz>
# Maintainer: Matthias Ahouansou <matthias@ahouansou.cz>
pkgname=mautrix-gmessages
pkgver=0.4.0
pkgrel=1
pkgdesc="Matrix-Google Messages puppeting bridge"
url="https://go.mau.fi/mautrix-gmessages/"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go olm-dev sqlite-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mautrix/gmessages/archive/v$pkgver.tar.gz
	mautrix-gmessages.initd
	mautrix-gmessages.confd
	default-log-dir.patch
	"
builddir="$srcdir/gmessages-$pkgver"
options="net"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CFLAGS="$CFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	go build
}

check() {
	go test -v ./...
}

package() {
	install -Dm755 mautrix-gmessages \
		-t "$pkgdir"/usr/bin/
	install -Dm644 example-config.yaml \
		-t "$pkgdir"/etc/mautrix-gmessages/

	install -Dm755 "$srcdir"/mautrix-gmessages.initd \
		"$pkgdir"/etc/init.d/mautrix-gmessages
	install -Dm644 "$srcdir"/mautrix-gmessages.confd \
		"$pkgdir"/etc/conf.d/mautrix-gmessages

	install -Dm 644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
}

sha512sums="
5155910eff8f5da6f28ab264439dd1990eb07116f25744f4681e41c9bb794ae73ef997760193e439674c55bcb26c5d457c1c07b2e9b277afd61c07aed6a0b10f  mautrix-gmessages-0.4.0.tar.gz
ed957641bdc1c56f7bea90db0fe4b845e5823323801033c710706116a9a06f98f2a808b8daa244f04b78676d595f12822040ff0b0863457a05222aac0c76750b  mautrix-gmessages.initd
3332b10948fc07845b3b9a775bbb01057d2e6c768e25b429a451dbfb668195eb9f2c1d6b435a944aa7e5618b6ae609fb16e471696176fe3ae0768dffec6618e5  mautrix-gmessages.confd
336298e0506bb3056733499098c291376e1777a24c994bdb92e4b2d62e954a59cddb66e60ce04100a86bc9ef4b7eb95353e003f9a3db2971040b72c9df0cc21b  default-log-dir.patch
"
